﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PurchaseManagementSystem.DBModel;
using System.Data.SqlClient;


namespace PurchaseManagementSystem
{
    /// <summary>
    /// 仓库部提交订单__王佳
    /// </summary>
    public partial class  Add_Order : Form
    {
        /// <summary>
        /// 订单编号
        /// </summary>
        private int OrderID = 0;

        public int Order_ID
        {
            get { return OrderID; }
            set { OrderID = int.Parse(tb_OrderID.Text); }  
        }

        /// <summary>
        /// 商品编号
        /// </summary>
        private int ComID = 0;   
        public int Com_ID
        {
            get { return ComID; }
            set { ComID = int.Parse(tb_ComID.Text); }
        }

        /// <summary>
        /// 商品数量
        /// </summary>
        private int ComNum = 0;     
        public int Com_Num
        {
            get { return ComNum; }
            set { ComNum = int.Parse(tb_ComNum.Text); }
        }

        /// <summary>
        /// 订货员编号
        /// </summary>
        private int EmployeeID = 0;

        public int Employee_ID
        {
            get { return EmployeeID; }
            set { EmployeeID = int.Parse(tb_EmployeeID.Text); }
        }

        public DateTime OrderTime = new DateTime();

        public Add_Order()
        {
            InitializeComponent();
        }

        private void Add_Order_Load(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try 
            {
                if (tb_OrderID.Text == "")
                {
                    MessageBox.Show("请输入订单编号！");
                }

                else if (tb_EmployeeID.Text == "")
                {
                    MessageBox.Show("请输入员工编号！");
                }

                else if (tb_ComID.Text == "")
                {
                    MessageBox.Show("请输入商品编号！");
                }

                else if (tb_ComNum.Text == "")
                {
                    MessageBox.Show("请输入需求数量！");
                }

                else
                {
                    Order_ID = Convert.ToInt32(tb_OrderID.Text);
                    Employee_ID = Convert.ToInt32(tb_EmployeeID.Text);
                    Com_ID = Convert.ToInt32(tb_ComID.Text);
                    Com_Num = Convert.ToInt32(tb_ComNum.Text);
                    DateTime OrderTime = DateTime.Now;
                    // OrderTime.ToString();
                    MessageBox.Show("  订单编号" + "              " + Order_ID.ToString() + Environment.NewLine
                                  + "订货员编号" + "             " + Employee_ID.ToString() + Environment.NewLine
                                  + "  商品编号" + "              " + Com_ID.ToString() + Environment.NewLine
                                  + "  商品数量" + "              " + Com_Num.ToString() + Environment.NewLine
                                  + "  生成时间" + "              " + OrderTime);

                    DBServer.Insertinto_initOrder(Order_ID, Employee_ID, Com_ID, OrderTime, Com_Num);
                    warehouse ware = new warehouse(Order_ID, Employee_ID, Com_ID);
                    ware.GetAllOrder();
                    PurchasePart pur = new PurchasePart(Order_ID, Employee_ID, Com_ID);
                    pur.GetAllOrder();
                    MessageBox.Show("添加成功！\n 请继续添加或退出程序");
                    Reset();
                }

            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message.ToString() + "添加失败！\n请输入正确的数据！");
            }

            
        }

        private void Reset()
        {
            button1.Text = "继续添加";
            tb_OrderID.Text = null;
            tb_ComID.Text = null;
            tb_ComNum.Text = null;
            tb_EmployeeID.Text = null;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

    }
}
